home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / ProgrammeDisplay.cs676 < prev    next >
Text File  |  2008-04-02  |  111KB  |  1,987 lines

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.UI.WebControls;
  6. using GBPVR.Public;
  7.  
  8. namespace gbweb.classes
  9. {
  10.     /// <summary>
  11.     /// Summary description for ProgrammeDisplay.
  12.     /// </summary>
  13.     /// 
  14.     /// 
  15.     public class ProgrammeDisplay : IDisposable
  16.     {
  17.  
  18.         private string SortBy;
  19.         private string SecondarySortBy = "mrs_title";
  20.         private bool ExtendedEWAEnabled = false;
  21.         
  22.         public ProgrammeDisplay()
  23.         {
  24.             if (getExtendedEWA())
  25.             {
  26.                 ExtendedEWA.OpenExtendedEWADB();
  27.             }
  28.         }
  29.  
  30.         #region IDisposable Members
  31.  
  32.         public void Dispose()
  33.         {
  34.             if (getExtendedEWA())
  35.             {
  36.                 //Close the ExtendedEWA DB
  37.                 ExtendedEWA.CloseExtendedEWADB();
  38.             }
  39.         }
  40.  
  41.         #endregion
  42.  
  43.         #region ExtendedEWA Detection
  44.  
  45.         private static bool ExtendedEWAToolCheck;
  46.         private static bool ExtendedEWALoaded = false;
  47.         private static bool getExtendedEWA()
  48.         {
  49.             if (!ExtendedEWALoaded)
  50.             {
  51.                 ExtendedEWAToolCheck = ExtendedEWA.Initialize();
  52.                 ExtendedEWALoaded = true;
  53.             }
  54.             return ExtendedEWAToolCheck;
  55.         }
  56.         #endregion
  57.  
  58.         public void FillProgrammeDisplay(HttpServerUtility Server, TableCell colShow, Programme programme, ScheduledRecording scheduledRecording, bool highlightRecordedShows)
  59.         {
  60.             //**************
  61.             //If you add functionality in this method you should review the FillProgrammeTreeArrayItem method as well
  62.             //**************
  63.             //
  64.             //This method fills a TableCell object with the formatted HTML code that is displayed
  65.  
  66.             Settings guideParams = Global.Settings;
  67.             string title = string.Empty;
  68.             string subtitle = string.Empty;
  69.             string href = null;
  70.             string onclick = string.Empty;
  71.             bool externallinks = true;
  72.             string description = string.Empty;
  73.             bool showAsRecording = false;
  74.  
  75.             if (scheduledRecording != null)
  76.             {
  77.                 switch (scheduledRecording.getRecordingType())
  78.                 {
  79.                     case ScheduledRecording.TYPE_RECORD_ONCE:
  80.                         if (programme == null) 
  81.                         {
  82.                             if (scheduledRecording.getFileName() != null && scheduledRecording.getFileName().Length > 0)
  83.                             {
  84.                                 title = "Manual Recording: " + scheduledRecording.getFileName();
  85.                             }
  86.                             else
  87.                             {
  88.                                 title = "Manual Recording";
  89.                             }
  90.                             externallinks = false;
  91.                         }
  92.                         break;
  93.                     default:
  94.                         title = scheduledRecording.getFileName();
  95.                         href = "Details.aspx?rid=" + scheduledRecording.getOID();
  96.                         onclick = " onclick=\"EditPop5(this.href,'Add2');return false;\"";
  97.                         programme = null;
  98.                         break;
  99.                 }
  100.                 if (highlightRecordedShows) showAsRecording = true;
  101.             }
  102.  
  103.             ExtendedEWAEnabled = false;
  104.             if (programme != null)
  105.             {
  106.                 //Check to see if the ExtendedEWA DB is available
  107.                 ExtendedEWAEnabled = getExtendedEWA();
  108.  
  109.                 title = programme.getTitle();
  110.                 string extralinks = string.Empty;
  111.                 const string spacer = "<br/><img height=\"4\" src=\"public/t.gif\" border=\"0\"><br/>";
  112.  
  113.                 // Show the programme description for all EPG Users
  114.                 if (guideParams.showDescription)
  115.                 {
  116.                     description = programme.getDescription();
  117.                     // If the description is found space it down two lines from the show name and title
  118.                     if (description.Length > 0)
  119.                     {
  120.                         description = spacer + description;
  121.                     }
  122.                 subtitle = programme.getSubTitle().Replace("\"", "''");
  123.                     if (subtitle.Length > 0)
  124.                     {
  125.                         // If there's no description, then add the subtitle as the description
  126.                         if (description.Length == 0 && !guideParams.showSubtitle)
  127.                         {
  128.                             description = spacer + subtitle;
  129.                         }
  130.                     }
  131.                 }
  132.                 // If you are not displaying the description but there is a subtitle then set the variable title to SubTitle
  133.                 else if (guideParams.showSubtitle)
  134.                 {
  135.                     subtitle = programme.getSubTitle().Replace("\"", "''");
  136.                 }
  137.  
  138.                 // Add a double line break if there are other things to display below the description
  139.                 if ((guideParams.showGenre != "noGenre") || (guideParams.showRating) || (ExtendedEWAEnabled && (guideParams.showNew || guideParams.showCredits)))
  140.                 {
  141.                     description += spacer + " ";
  142.                 }
  143.  
  144.                 // Retrieve the rating for the show
  145.                 if (guideParams.showRating)
  146.                 {
  147.                     string rating = programme.getRating();
  148.                     //Since this is the first item being added to the variable extalinks we don't need to add line breaks since it was taken care of by
  149.                     if (rating != null && rating.Length > 0)
  150.                     {
  151.                         extralinks += "Rated: " + programme.getRating();
  152.                     }
  153.                 }
  154.  
  155.                 // Add the show Genre to the line
  156.                 if (guideParams.showGenre != "noGenre")
  157.                 {
  158.                     ArrayList genreCheck = programme.getGenreList();
  159.                     for (int unknownPos = genreCheck.BinarySearch("unknown", new CaseInsensitiveComparer()); unknownPos > -1;
  160.                              unknownPos = genreCheck.BinarySearch("unknown", new CaseInsensitiveComparer()))
  161.                     {
  162.                         genreCheck.RemoveAt(unknownPos);
  163.                     }
  164.                     for (int unknownPos = genreCheck.BinarySearch(string.Empty, new CaseInsensitiveComparer()); unknownPos > -1;
  165.                         unknownPos = genreCheck.BinarySearch(string.Empty, new CaseInsensitiveComparer()))
  166.                     {
  167.                         genreCheck.RemoveAt(unknownPos);
  168.                     }
  169.                     if (genreCheck.Count > 0)
  170.                     {
  171.                         //If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  172.                         if (extralinks.Length > 0) extralinks += "<br>";
  173.                         if (guideParams.showGenre == "allGenre")
  174.                         {
  175.                             extralinks += "Genre" + (genreCheck.Count > 1 ? "s" : string.Empty) + ": " + string.Join(", ", (string[])genreCheck.ToArray(typeof(string)));
  176.                         }
  177.                         else
  178.                         {
  179.                             extralinks += "Genre: " + genreCheck[0];
  180.                         }
  181.                     }
  182.                 }
  183.  
  184.                 // If the user has ExtendedEWA append additional information to the description when found
  185.                 if (ExtendedEWAEnabled)
  186.                 {
  187.                     string programUniqueIdentifier = programme.getUniqueProgrammeIdentifier();
  188.                     // Pull the Airdate of the Show or the Release Year of the movie and the Start Rating for Movie
  189.                     string[] programInfo = ExtendedEWA.GetProgramInfo(programUniqueIdentifier);
  190.  
  191.                     if (guideParams.showAirDate || guideParams.showStarRating)
  192.                     {
  193.                         if (programInfo.Length > 0)
  194.                         {
  195.                             if (programUniqueIdentifier.StartsWith("MV"))
  196.                             {
  197.                                 if ((guideParams.showAirDate) && (programInfo[0] != "0"))
  198.                                 {
  199.                                     // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  200.                                     if (extralinks.Length > 0) extralinks += "<br>";
  201.                                     extralinks += " Movie Release Year: " + programInfo[0].ToString();
  202.                                 }
  203.                                 if ((guideParams.showStarRating) && (programInfo[2] != "none"))
  204.                                 {
  205.                                     // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  206.                                     if (extralinks.Length > 0) extralinks += "<br>";
  207.                                     extralinks += " Star Rating: " + programInfo[2];
  208.                                 }
  209.                             }
  210.                             else
  211.                             {
  212.                                 if ((guideParams.showAirDate) && (programInfo[1] != "none"))
  213.                                 {
  214.                                     // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  215.                                     if (extralinks.Length > 0) extralinks += "<br>";
  216.                                     extralinks += " Original Air Date: " + programInfo[1];
  217.                                 }
  218.                             }
  219.                         }
  220.                     }
  221.  
  222.                     // Check the ExtendedEWA supplemental database to see if the show is a new show
  223.                     if (guideParams.showNew)
  224.                     {
  225.                         if (ExtendedEWA.IsNew(programUniqueIdentifier))
  226.                         {
  227.                             // If show is a new show tag an indicator at the end of the description indicating so
  228.                             // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  229.                             if (extralinks.Length > 0) extralinks += "<br>";
  230.                             extralinks += "<b> (* New *)</b>";
  231.                         }
  232.                         //We need to check to see if the airdate is >= to today since the New show identifier is not reliable.
  233.                         //If the airdate is >= programme air date then we can assume it is a new show
  234.                         else if (programInfo.Length > 0)
  235.                         {
  236.                             if (!programUniqueIdentifier.StartsWith("MV"))
  237.                             {
  238.                                 if (programInfo[1] != "none")
  239.                                 {
  240.                                     try
  241.                                     {
  242.                                         DateTime airDate = Convert.ToDateTime(programInfo[1]);
  243.                                         if (airDate.Date >= programme.getStartTime().Date)
  244.                                         {
  245.                                             if (extralinks.Length > 0) extralinks += "<br>";
  246.                                             extralinks += "<b> (* New *)</b>";
  247.                                         }
  248.                                     }
  249.                                     catch (Exception e)
  250.                                     {
  251.                                     }
  252.                                 }
  253.                             }
  254.                         }
  255.                     }
  256.  
  257.                     if (guideParams.showHD)
  258.                     {
  259.                         if (ExtendedEWA.IsHD(programUniqueIdentifier))
  260.                         {
  261.                             // If show is a High Def (HD) tag an indicator at the end of the description indicating the show is in HD
  262.                             // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  263.                             if (extralinks.Length > 0) extralinks += "<br>";
  264.                             extralinks += "<b> HD </b>";
  265.                         }
  266.                     }
  267.  
  268.                     // Provide a link to see Cast information
  269.                     if (guideParams.showCredits)
  270.                     {
  271.                         // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  272.                         if (extralinks.Length > 0) extralinks += "<br>";
  273.                         extralinks += "(<a href=\"Credits.aspx?id=" + programme.getOID() + "\" onclick=\"EditPop2(this.href,'Add1');return false;\">Credits</a>)";
  274.                     }
  275.                 }
  276.  
  277.                 href = "Details.aspx?id=" + programme.getOID();
  278.                 if (scheduledRecording != null)
  279.                 {
  280.                     if (highlightRecordedShows) showAsRecording = true;
  281.                     href += "&rid=" + scheduledRecording.getOID();
  282.                 }
  283.                 onclick = " onclick=\"EditPop5(this.href,'Add2');return false;\"";
  284.  
  285.                 if (extralinks != string.Empty)
  286.                 {
  287.                     description = description + extralinks;
  288.                 }
  289.                 
  290.             }
  291.             else
  292.             {
  293.                 if (scheduledRecording.getRecordingType() != ScheduledRecording.TYPE_RECORD_SEASON)
  294.                 {
  295.                     if (scheduledRecording.getFileName() != null && scheduledRecording.getFileName().Length > 0)
  296.                     {
  297.                         title = "Manual Recording: " + scheduledRecording.getFileName();
  298.                     }
  299.                     else
  300.                     {
  301.                         title = "Manual Recording";
  302.                     }
  303.                     externallinks = false;
  304.                 }
  305.             }
  306.  
  307.             // Add external links (these must be added in reverse order)
  308.  
  309.             ///////////////// Paid Programming ==> No Links ////////////////////////
  310.             if (title != null && title != "Paid Programming" && programme != null)
  311.             {
  312.                 string programUniqueIdentifier = programme.getUniqueProgrammeIdentifier();
  313.  
  314.                 // Add external links (these must be added in reverse order)
  315.                 /////////////////////////// Wiki /////////////////////////////////
  316.                 // Straight Forward Search of Wikipedia ( using Wikipedia Only )
  317.  
  318.                 // Show the show link to Wikipedia for all EPG Users
  319.  
  320.                 if (externallinks && guideParams.showWiki)
  321.                 {
  322.                     description = " (<a href=\"http://en.wikipedia.org/w/index.php?title=Special:Search&search=%22" +
  323.                         Server.UrlEncode(title) + "%22" +
  324.                         "\" target=\"_blank\">Wiki</a>)" + description;
  325.                 }
  326.  
  327.                 /////////////////////////// TV.Com /////////////////////////////////
  328.                 // Google "I'm Feeling Lucky" for title ( and subtitle when available ) against "site:tv.com"
  329.                 // Backup of direct TV.Com title search available as an *ASTRIX*
  330.                 // Links Not available if program is a Movie (MV)
  331.  
  332.                 // Show the show link to TV.Com for all EPG Users
  333.                 if (externallinks && guideParams.showTVCom && !programUniqueIdentifier.StartsWith("MV"))
  334.                 {
  335.                     description = "(<a href=\"http://www.tv.com/search.php?type=11&stype=program&qs=%22" +
  336.                         Server.UrlEncode(title) + "%22" +
  337.                         "\" target=\"_blank\">*</a>)" + description;
  338.                     if (subtitle != "")
  339.                     {
  340.                         description = " (<a href=\"http://www.google.com/search?hl=en&q=site:tv.com+%22" +
  341.                             Server.UrlEncode(title) + "%22+%22" + Server.UrlEncode(subtitle) + "%22+%22read+episode+recap%22" + "&btnI=I'm+Feeling+Lucky" +
  342.                             "\" target=\"_blank\">TV.Com</a>)" + description;
  343.                     }
  344.                     else
  345.                     {
  346.                         description = " (<a href=\"http://www.google.com/search?hl=en&q=site:tv.com+%22" +
  347.                     Server.UrlEncode(title) + "%22+premiered+&btnI=I'm+Feeling+Lucky" +
  348.                     "\" target=\"_blank\">TV.Com</a>)" + description;
  349.                     }
  350.                 }
  351.  
  352.                 /////////////////////////// NetFlix /////////////////////////////////
  353.                 // Google "I'm Feeling Lucky" for title against "site:netflix.com/Movie"
  354.                 // Backup of direct NetFlix.Com title search available as an *ASTRIX*
  355.                 // Links Only Available if program is a Movie (MV)
  356.  
  357.                 // Show the show link to Netflix for all EPG Users
  358.                 if (externallinks && guideParams.showNetflix && programUniqueIdentifier.StartsWith("MV"))
  359.                 {
  360.                     description = "(<a href=\"http://www.netflix.com/Search?dtl=1&type=title&v1=%22" +
  361.                         Server.UrlEncode(title) + "%22" +
  362.                         "\" target=\"_blank\">*</a>)" + description;
  363.                     description = " (<a href=\"http://www.google.com/search?hl=en&q=site:netflix.com/Movie+%22" +
  364.                         Server.UrlEncode(title) + "%22&btnI=I%27m+Feeling+Lucky" +
  365.                         "\" target=\"_blank\">NetFlix</a>)" + description;
  366.                 }
  367.  
  368.                 /////////////////////////// IMDB /////////////////////////////////
  369.                 // Google "I'm Feeling Lucky" for title ( and subtitle when avaiable ) against "site:imdb.com/title"
  370.                 // Backup of direct IMDB.Com title ( and subtitle ) search available as an *ASTRIX*
  371.                 // Links for title only if program is a Movie (MV) or Show (SH), subtitle links possible if (EP)
  372.  
  373.                 // Show the show link to IMDB for all EPG Users
  374.                 if (externallinks && guideParams.showIMDB)
  375.                 {
  376.                     if (!programUniqueIdentifier.StartsWith("MV"))
  377.                     {// Is An Episode
  378.                         if (subtitle != "")
  379.                         {
  380.                             description = "(<a href=\"http://www.imdb.com/find?s=tt&q=%22" +
  381.                                 Server.UrlEncode(title) + "%22" + "&s=ep&q=%22" + Server.UrlEncode(subtitle) + "%22" +
  382.                                 "\" target=\"_blank\">*</a>)" + description;
  383.                             description = " (<a href=\"http://www.google.com/search?hl=en&q=site%3Aimdb.com/title+%22" +
  384.                                 Server.UrlEncode(title) + "%22+%22" + Server.UrlEncode(subtitle) + "%22+%22rate+this+title%22&btnI=I%27m+Feeling+Lucky" +
  385.                                 "\" target=\"_blank\">IMDB</a>)" + description;
  386.                         }
  387.                         else
  388.                         {
  389.                             description = "(<a href=\"http://www.imdb.com/find?s=tt&q=%22" +
  390.                                 Server.UrlEncode(title) + "%22" +
  391.                                 "\" target=\"_blank\">*</a>)" + description;
  392.                             description = " (<a href=\"http://www.google.com/search?hl=en&q=site%3Aimdb.com/title+%22" +
  393.                                 Server.UrlEncode(title) + "+%22TV-Series%22+%22rate+this+title%22&btnI=I%27m+Feeling+Lucky" +
  394.                                 "\" target=\"_blank\">IMDB</a>)" + description;
  395.                         }
  396.                     }
  397.                     else
  398.                     {// Is a Movie
  399.                         description = "(<a href=\"http://www.imdb.com/find?s=tt&q=%22" +
  400.                             Server.UrlEncode(title) + "%22" +
  401.                             "\" target=\"_blank\">*</a>)" + description;
  402.                         description = " (<a href=\"http://www.google.com/search?hl=en&q=site%3Aimdb.com/title+%22" +
  403.                             Server.UrlEncode(title) + "%22+%22rate+this+title%22&btnI=I%27m+Feeling+Lucky" +
  404.                             "\" target=\"_blank\">IMDB</a>)" + description;
  405.                     }
  406.                 }
  407.  
  408.             }//end Paid Programming
  409.  
  410.             string spanclass;
  411.             if (showAsRecording)
  412.             {
  413.                 int showStatus = scheduledRecording.getRecordingStatus();
  414.                 switch (showStatus)
  415.                 {
  416.                     case ScheduledRecording.STATUS_PENDING:
  417.                         colShow.CssClass = "pending";
  418.                         spanclass = "pending";
  419.                         break;
  420.                     case ScheduledRecording.STATUS_IN_PROGRESS:
  421.                         colShow.CssClass = "inprogress";
  422.                         spanclass = "inprogress";
  423.                         break;
  424.                     case ScheduledRecording.STATUS_COMPLETED:
  425.                         colShow.CssClass = "available";
  426.                         spanclass = "available";
  427.                         break;
  428.                     case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  429.                         colShow.CssClass = "failed";
  430.                         spanclass = "failed";
  431.                         break;
  432.                     case ScheduledRecording.STATUS_CONFLICT:
  433.                         colShow.CssClass = "conflict";
  434.                         spanclass = "conflict";
  435.                         break;
  436.                     default:
  437.                         colShow.CssClass = "recorded";
  438.                         spanclass = "recorded";
  439.                         break;
  440.                 }
  441.             }
  442.             else
  443.             {
  444.                 colShow.CssClass = "listing";
  445.                 spanclass = "listdesc";
  446.             }
  447.  
  448.             title = "<span class=\"title\">" + title + "</span>";
  449.             if (subtitle.Length > 0) title += ": <span class=\"subtitle\">" +  subtitle + "</span>";
  450.             title = "<b>" + title + "</b>";
  451.             if (href != null) title = "<a href=\"" + href + "\"" + onclick + ">" + title + "</a>";
  452.             if (description.Length > 0) title += "<span class=\"" + spanclass + "\">" + description + "</span>";
  453.             colShow.Text = title;
  454.         }
  455.  
  456.         public void FillProgrammeTreeArrayItem(ProgramTreeItem treeItem, HttpServerUtility Server, Programme programme, ScheduledRecording scheduledRecording, bool highlightRecordedShows, Channel channel)
  457.         {
  458.             //**************
  459.             //If you add functionality in this method you should review the FillProgramme method as well
  460.             //**************
  461.             //
  462.             //This method fills a ProgrammeTreeItem object with the formatted HTML code that is displayed
  463.  
  464.             Settings guideParams = Global.Settings;
  465.             string title = string.Empty;
  466.             string subtitle = string.Empty;
  467.             string title2 = string.Empty;
  468.             string subtitle2 = string.Empty;
  469.             string href = string.Empty;
  470.             string onclick = string.Empty;
  471.             string description = string.Empty;
  472.             bool showAsRecording = false;
  473.             bool ManualRecording = false;
  474.  
  475.             if (scheduledRecording != null)
  476.             {
  477.                 if (highlightRecordedShows) showAsRecording = true;
  478.             }
  479.  
  480.             if (programme != null)
  481.             {
  482.  
  483.                 //Check to see if the ExtendedEWA DB is available
  484.                 bool ExtendedEWAEnabled = getExtendedEWA();
  485.  
  486.                 //Set the onclick event variable
  487.                 onclick = " onclick=\"EditPop5(this.href,'Add2');return false;\"";
  488.                 //Set a default spacer variable
  489.                 const string spacer = "<img width=\"10\" height=\"4\" src=\"public/t.gif\" border=\"0\">";
  490.                 //Set the Title and Subtitle variables
  491.                 title = programme.getTitle().Replace("\"", "''");
  492.                 subtitle = programme.getSubTitle().Replace("\"", "''");
  493.                 title2 = programme.getTitle().Replace("\"", "''");
  494.                 subtitle2 = programme.getSubTitle().Replace("\"", "''");
  495.  
  496.                 treeItem.setTitle("<span class=\"listing\"> " + title + "</span>");
  497.                 treeItem.setRawTitle(programme.getTitle());
  498.  
  499.                 string subtitleFmt;
  500.                 if (subtitle.Length > 0)
  501.                 {
  502.                     subtitleFmt = "<span class=\"listing\">" + "Subtitle: " + "</span>";
  503.                     subtitleFmt += "<span class=\"subtitle\">" + subtitle + "</span>";
  504.                 }
  505.                 else
  506.                 {
  507.                     subtitleFmt = "<span class=\"listing\">" + "Subtitle: " + "</span>";
  508.                     subtitleFmt += "<span class=\"subtitle\">" + "None Available" + "</span>";
  509.                 }
  510.                 subtitle = subtitleFmt;
  511.                 treeItem.setSubTitle(subtitleFmt);
  512.  
  513.                 string desc = programme.getDescription();
  514.                 if (desc.Length > 0)
  515.                 {
  516.                     treeItem.setDescription("<span class=\"listdesc\">" + programme.getDescription() + "</span>");
  517.                 }
  518.                 
  519.                 // Retrieve the rating for the show
  520.                 if (guideParams.showRating)
  521.                 {
  522.                     string rating = programme.getRating();
  523.                     //Since this is the first item being added to the variable extalinks we don't need to add line breaks since it was taken care of by
  524.                     if (rating != null && rating.Length > 0)
  525.                     {
  526.                         treeItem.setRating("<span class=\"listing\">" + "Rated: " + programme.getRating() + "</span>");
  527.                     }
  528.                 }
  529.  
  530.                 // Add the show Genre
  531.                 if (guideParams.showGenre != "noGenre")
  532.                 {
  533.                     ArrayList genreCheck = programme.getGenreList();
  534.                     for (int unknownPos = genreCheck.BinarySearch("unknown", new CaseInsensitiveComparer()); unknownPos > -1;
  535.                              unknownPos = genreCheck.BinarySearch("unknown", new CaseInsensitiveComparer()))
  536.                     {
  537.                         genreCheck.RemoveAt(unknownPos);
  538.                     }
  539.                     for (int unknownPos = genreCheck.BinarySearch(string.Empty, new CaseInsensitiveComparer()); unknownPos > -1;
  540.                         unknownPos = genreCheck.BinarySearch(string.Empty, new CaseInsensitiveComparer()))
  541.                     {
  542.                         genreCheck.RemoveAt(unknownPos);
  543.                     }
  544.                     if (genreCheck.Count > 0)
  545.                     {
  546.                         //If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  547.                         if (guideParams.showGenre == "allGenre")
  548.                         {
  549.                             treeItem.setGenre("<span class=\"listing\">" + "Genre" + (genreCheck.Count > 1 ? "s" : string.Empty) + ": " + string.Join(", ", (string[])genreCheck.ToArray(typeof(string))) + "</span>");
  550.                         }
  551.                         else
  552.                         {
  553.                             treeItem.setGenre("<span class=\"listing\">" + "Genre: " + genreCheck[0] + "</span>");
  554.                         }
  555.                     }
  556.                     else
  557.                     {
  558.                         treeItem.setGenre("<span class=\"listing\">" + "No Genre Found:" + "</span>");
  559.                     }
  560.                 }
  561.                 
  562.                 // If the user has ExtendedEWA append additional information to the description when found
  563.                 if (ExtendedEWAEnabled)
  564.                 {
  565.                     string programUniqueIdentifier = programme.getUniqueProgrammeIdentifier();
  566.                     // Pull the Airdate of the Show or the Release Year of the movie and the Start Rating for Movie
  567.                     string[] programInfo = ExtendedEWA.GetProgramInfo(programUniqueIdentifier);
  568.  
  569.                     if (guideParams.showAirDate || guideParams.showStarRating)
  570.                     {
  571.                         if (programInfo.Length > 0)
  572.                         {
  573.                             if (programUniqueIdentifier.StartsWith("MV"))
  574.                             {
  575.                                 if ((guideParams.showAirDate) && (programInfo[0] != "0"))
  576.                                 {
  577.                                     treeItem.setReleaseYear("<span class=\"listing\">" + "Movie Release Year: " + programInfo[0].ToString() + "</span>");
  578.                                 }
  579.                                 if ((guideParams.showStarRating) && (programInfo[2] != "none"))
  580.                                 {
  581.                                     treeItem.setStarRating("<span class=\"listing\">" + "Star Rating: " + programInfo[2] + "</span>");
  582.                                 }
  583.                             }
  584.                             else
  585.                             {
  586.                                 if ((guideParams.showAirDate) && (programInfo[1] != "none"))
  587.                                 {
  588.                                     treeItem.setOriginalAirDate("<span class=\"listing\">" + "Original Air Date: " + programInfo[1] + "</span>");
  589.                                     treeItem.setRawOriginalAirDate(programInfo[1]);
  590.                                 }
  591.                             }
  592.                         }
  593.                     }
  594.                     
  595.                     // Check the ExtendedEWA supplemental database to see if the show is a new show
  596.                     if (guideParams.showNew)
  597.                     {
  598.                         if (ExtendedEWA.IsNew(programUniqueIdentifier))
  599.                         {
  600.                             treeItem.setNew_Show("<span class=\"new_show\">" + "<b> (* New *)</b>" + "</span>");
  601.                         }
  602.                         //We need to check to see if the airdate is >= to today since the New show identifier is not reliable.
  603.                         //If the airdate is >= programme air date then we can assume it is a new show
  604.                         else if (programInfo.Length > 0)
  605.                         {
  606.                             if (!programUniqueIdentifier.StartsWith("MV"))
  607.                             {
  608.                                 if (programInfo[1] != "none")
  609.                                 {
  610.                                     try
  611.                                     {
  612.                                         DateTime airDate = Convert.ToDateTime(programInfo[1]);
  613.                                         if (airDate.Date >= programme.getStartTime().Date)
  614.                                         {
  615.                                             treeItem.setNew_Show("<span class=\"new_show\">" + "<b> (* New *)</b>" + "</span>");
  616.                                         }
  617.                                     }
  618.                                     catch (Exception e)
  619.                                     {
  620.                                     }
  621.                                 }
  622.                             }
  623.                         }
  624.                     }
  625.  
  626.                     if (guideParams.showHD)
  627.                     {
  628.                         if (ExtendedEWA.IsHD(programUniqueIdentifier))
  629.                         {
  630.                             // If show is a High Def (HD) tag an indicator at the end of the description indicating the show is in HD
  631.                             // If another extralink was previously added we want to single space this one down otherwise no extra line is needed
  632.                             treeItem.setHD("<span class=\"subtitle\">" + "<b> HD </b>" + "</span>");
  633.                         }
  634.                     }
  635.  
  636.                     // Provide a link to see Cast information
  637.                     if (guideParams.showCredits)
  638.                     {
  639.                         treeItem.setCredits("<span class=\"listing\">" + "<a href=\"Credits.aspx?id=" + programme.getOID() + "\" onclick=\"EditPop2(this.href,'Add1');return false;\">Credits</a>" + "</span>");
  640.                     }
  641.                 }
  642.  
  643.  
  644.                 if (showAsRecording)
  645.                 {
  646.                     int showStatus = scheduledRecording.getRecordingStatus();
  647.                     switch (showStatus)
  648.                     {
  649.                         case ScheduledRecording.STATUS_PENDING:
  650.                             treeItem.setRecordingDisplayClass("pending");
  651.                             treeItem.setStatus("Pending");
  652.                             break;
  653.                         case ScheduledRecording.STATUS_IN_PROGRESS:
  654.                             treeItem.setRecordingDisplayClass("inprogress");
  655.                             treeItem.setStatus("In-Progress");
  656.                             break;
  657.                         case ScheduledRecording.STATUS_COMPLETED:
  658.                             treeItem.setRecordingDisplayClass("available");
  659.                             treeItem.setStatus("Available");
  660.                             break;
  661.                         case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  662.                             treeItem.setRecordingDisplayClass("failed");
  663.                             treeItem.setStatus("Failed");
  664.                             break;
  665.                         case ScheduledRecording.STATUS_CONFLICT:
  666.                             treeItem.setRecordingDisplayClass("conflict");
  667.                             treeItem.setStatus("Conflict");
  668.                             break;
  669.                         case ScheduledRecording.STATUS_PLACE_HOLDER:
  670.                             treeItem.setRecordingDisplayClass("reoccurring");
  671.                             treeItem.setStatus("Reoccurring");
  672.                             break;    
  673.                         default:
  674.                             treeItem.setRecordingDisplayClass("listing");
  675.                             treeItem.setStatus("Unknown");
  676.                             break;
  677.                     }
  678.                 }
  679.                 else
  680.                 {
  681.                     treeItem.setRecordingDisplayClass("listing");
  682.                 }
  683.  
  684.                 treeItem.setAirDate("<span class=\"listing\">" + programme.getStartTime().ToLongDateString() + " " + programme.getStartTime().ToShortTimeString() + " - " + programme.getEndTime().ToShortTimeString() + "</span>");
  685.                 treeItem.setrawAirDateStartTime(programme.getStartTime());
  686.                 treeItem.setrawAirDateEndTime(programme.getEndTime());
  687.  
  688.                 if (channel != null)
  689.                 {
  690.                     treeItem.setChannelDisplay("<span class=\"listing\">" + channel.getName() + "</span>");
  691.                     treeItem.setChannelName(channel.getName());
  692.                     treeItem.setChannel(channel.getChannelNumber());
  693.                 }
  694.                 else
  695.                 {
  696.                     treeItem.setChannelDisplay("No Channel Info Found");
  697.                     treeItem.setChannelName("No Channel Info Found");
  698.                 }
  699.                 
  700.  
  701.                 href = "Details.aspx?id=" + programme.getOID();
  702.                 if (scheduledRecording != null)
  703.                 {
  704.                     href += "&rid=" + scheduledRecording.getOID();
  705.                 }
  706.             }
  707.             else
  708.             {
  709.                 ManualRecording = true;
  710.                 string subtitleFmt = string.Empty;
  711.                 if (scheduledRecording.getRecordingType() != ScheduledRecording.TYPE_RECORD_SEASON)
  712.                 {
  713.                     treeItem.setGenre("<span class=\"listing\">" + "Genre: Manual Recording" + "</span>");
  714.                     if (scheduledRecording.getFileName() != null && scheduledRecording.getFileName().Length > 0)
  715.                     {
  716.                         title = "Manual Recording: ";
  717.                         subtitleFmt = "<span class=\"listing\">" + "Subtitle: " + "</span>";
  718.                         subtitleFmt += "<span class=\"subtitle\">" + scheduledRecording.getFileName() + "</span>";
  719.                     }
  720.                     else
  721.                     {
  722.                         title = "Manual Recording";
  723.                         subtitleFmt = "<span class=\"listing\">" + "Subtitle: " + "</span>";
  724.                         subtitleFmt += "<span class=\"subtitle\">" + "None Available" + "</span>";
  725.                     }
  726.                 }
  727.                 else
  728.                 {
  729.                     title = scheduledRecording.getFileName();
  730.                     href = "Details.aspx?rid=" + scheduledRecording.getOID();
  731.                     title = "<a href=\"" + href + "\"" + "\" onclick=\"EditPop5(this.href,'Add1');return false;\">" + title + "</a>";
  732.  
  733.                     treeItem.setTitle("<span class=\"listing\"> " + title + "</span>");
  734.                     treeItem.setRawTitle(title);
  735.                     treeItem.setGenre("<span class=\"listing\">" + "Genre: Season Recording" + "</span>");
  736.                     if (scheduledRecording.getStartTime().Year != 0001)
  737.                     {
  738.                         subtitleFmt = "<span class=\"listing\">" + scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString() + "</span>";
  739.                     }
  740.                 }
  741.                 treeItem.setTitle("<span class=\"listing\"> " + title + "</span>");
  742.                 treeItem.setRawTitle(title);
  743.                 treeItem.setSubTitle(subtitleFmt);
  744.                 if (showAsRecording)
  745.                 {
  746.                     int showStatus = scheduledRecording.getRecordingStatus();
  747.                     switch (showStatus)
  748.                     {
  749.                         case ScheduledRecording.STATUS_PENDING:
  750.                             treeItem.setRecordingDisplayClass("pending");
  751.                             treeItem.setStatus("Pending");
  752.                             break;
  753.                         case ScheduledRecording.STATUS_IN_PROGRESS:
  754.                             treeItem.setRecordingDisplayClass("inprogress");
  755.                             treeItem.setStatus("In-Progress");
  756.                             break;
  757.                         case ScheduledRecording.STATUS_COMPLETED:
  758.                             treeItem.setRecordingDisplayClass("available");
  759.                             treeItem.setStatus("Available");
  760.                             break;
  761.                         case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  762.                             treeItem.setRecordingDisplayClass("failed");
  763.                             treeItem.setStatus("Failed");
  764.                             break;
  765.                         case ScheduledRecording.STATUS_CONFLICT:
  766.                             treeItem.setRecordingDisplayClass("conflict");
  767.                             treeItem.setStatus("Conflict");
  768.                             break;
  769.                         case ScheduledRecording.STATUS_PLACE_HOLDER:
  770.                             treeItem.setRecordingDisplayClass("reocurring");
  771.                             treeItem.setStatus("Reocurring");
  772.                             break;
  773.                         default:
  774.                             treeItem.setRecordingDisplayClass("listing");
  775.                             treeItem.setStatus("Unknown");
  776.                             break;
  777.                     }
  778.                 }
  779.                 else
  780.                 {
  781.                     treeItem.setRecordingDisplayClass("listing");
  782.                 }
  783.  
  784.                 if (channel != null)
  785.                 {
  786.                     treeItem.setChannelDisplay("<span class=\"listing\">" + channel.getName() + "</span>");
  787.                     treeItem.setChannelName(channel.getName());
  788.                 }
  789.                 else
  790.                 {
  791.                     treeItem.setChannelDisplay("No Channel Info Found");
  792.                     treeItem.setChannelName("No Channel Info Found");
  793.                 }
  794.  
  795.                 treeItem.setChannel(channel.getChannelNumber());
  796.             }
  797.  
  798.             // Add external links (these must be added in reverse order)
  799.             ///////////////// Paid Programming ==> No Links ////////////////////////
  800.             if (title != null && title != "Paid Programming" && programme != null)
  801.             {
  802.                 string programUniqueIdentifier = programme.getUniqueProgrammeIdentifier();
  803.  
  804.                 // Add external links (these must be added in reverse order)
  805.                 /////////////////////////// Wiki /////////////////////////////////
  806.                 // Straight Forward Search of Wikipedia ( using Wikipedia Only )
  807.  
  808.                 // Show the show link to Wikipedia for all EPG Users
  809.  
  810.                 if (guideParams.showWiki)
  811.                 {
  812.                     description = " (<a href=\"http://en.wikipedia.org/w/index.php?title=Special:Search&search=%22" +
  813.                         Server.UrlEncode(title) + "%22" +
  814.                         "\" target=\"_blank\">Wiki</a>)" + description;
  815.                 }
  816.  
  817.                 /////////////////////////// TV.Com /////////////////////////////////
  818.                 // Google "I'm Feeling Lucky" for title ( and subtitle when available ) against "site:tv.com"
  819.                 // Backup of direct TV.Com title search available as an *ASTRIX*
  820.                 // Links Not available if program is a Movie (MV)
  821.  
  822.                 // Show the show link to TV.Com for all EPG Users
  823.                 if (guideParams.showTVCom && !programUniqueIdentifier.StartsWith("MV"))
  824.                 {
  825.                     description = "(<a href=\"http://www.tv.com/search.php?type=11&stype=program&qs=%22" +
  826.                         Server.UrlEncode(title) + "%22" +
  827.                         "\" target=\"_blank\">*</a>)" + description;
  828.                     if (subtitle != "")
  829.                     {
  830.                         description = " (<a href=\"http://www.google.com/search?hl=en&q=site:tv.com+%22" +
  831.                             Server.UrlEncode(title) + "%22+%22" + Server.UrlEncode(subtitle) + "%22+%22read+episode+recap%22" + "&btnI=I'm+Feeling+Lucky" +
  832.                             "\" target=\"_blank\">TV.Com</a>)" + description;
  833.                     }
  834.                     else
  835.                     {
  836.                         description = " (<a href=\"http://www.google.com/search?hl=en&q=site:tv.com+%22" +
  837.                     Server.UrlEncode(title) + "%22+premiered+&btnI=I'm+Feeling+Lucky" +
  838.                     "\" target=\"_blank\">TV.Com</a>)" + description;
  839.                     }
  840.                 }
  841.  
  842.                 /////////////////////////// NetFlix /////////////////////////////////
  843.                 // Google "I'm Feeling Lucky" for title against "site:netflix.com/Movie"
  844.                 // Backup of direct NetFlix.Com title search available as an *ASTRIX*
  845.                 // Links Only Available if program is a Movie (MV)
  846.  
  847.                 // Show the show link to Netflix for all EPG Users
  848.                 if (guideParams.showNetflix && programUniqueIdentifier.StartsWith("MV"))
  849.                 {
  850.                     description = "(<a href=\"http://www.netflix.com/Search?dtl=1&type=title&v1=%22" +
  851.                         Server.UrlEncode(title) + "%22" +
  852.                         "\" target=\"_blank\">*</a>)" + description;
  853.                     description = " (<a href=\"http://www.google.com/search?hl=en&q=site:netflix.com/Movie+%22" +
  854.                         Server.UrlEncode(title) + "%22&btnI=I%27m+Feeling+Lucky" +
  855.                         "\" target=\"_blank\">NetFlix</a>)" + description;
  856.                 }
  857.  
  858.                 /////////////////////////// IMDB /////////////////////////////////
  859.                 // Google "I'm Feeling Lucky" for title ( and subtitle when avaiable ) against "site:imdb.com/title"
  860.                 // Backup of direct IMDB.Com title ( and subtitle ) search available as an *ASTRIX*
  861.                 // Links for title only if program is a Movie (MV) or Show (SH), subtitle links possible if (EP)
  862.  
  863.                 // Show the show link to IMDB for all EPG Users
  864.                 if (guideParams.showIMDB)
  865.                 {
  866.                     if (!programUniqueIdentifier.StartsWith("MV"))
  867.                     {// Is An Episode
  868.                         if (subtitle != "")
  869.                         {
  870.                             description = "(<a href=\"http://www.imdb.com/find?s=tt&q=%22" +
  871.                                 Server.UrlEncode(title) + "%22" + "&s=ep&q=%22" + Server.UrlEncode(subtitle) + "%22" +
  872.                                 "\" target=\"_blank\">*</a>)" + description;
  873.                             description = " (<a href=\"http://www.google.com/search?hl=en&q=site%3Aimdb.com/title+%22" +
  874.                                 Server.UrlEncode(title) + "%22+%22" + Server.UrlEncode(subtitle) + "%22+%22rate+this+title%22&btnI=I%27m+Feeling+Lucky" +
  875.                                 "\" target=\"_blank\">IMDB</a>)" + description;
  876.                         }
  877.                         else
  878.                         {
  879.                             description = "(<a href=\"http://www.imdb.com/find?s=tt&q=%22" +
  880.                                 Server.UrlEncode(title) + "%22" +
  881.                                 "\" target=\"_blank\">*</a>)" + description;
  882.                             description = " (<a href=\"http://www.google.com/search?hl=en&q=site%3Aimdb.com/title+%22" +
  883.                                 Server.UrlEncode(title) + "+%22TV-Series%22+%22rate+this+title%22&btnI=I%27m+Feeling+Lucky" +
  884.                                 "\" target=\"_blank\">IMDB</a>)" + description;
  885.                         }
  886.                     }
  887.                     else
  888.                     {// Is a Movie
  889.                         description = "(<a href=\"http://www.imdb.com/find?s=tt&q=%22" +
  890.                             Server.UrlEncode(title) + "%22" +
  891.                             "\" target=\"_blank\">*</a>)" + description;
  892.                         description = " (<a href=\"http://www.google.com/search?hl=en&q=site%3Aimdb.com/title+%22" +
  893.                             Server.UrlEncode(title) + "%22+%22rate+this+title%22&btnI=I%27m+Feeling+Lucky" +
  894.                             "\" target=\"_blank\">IMDB</a>)" + description;
  895.                     }
  896.                 }
  897.  
  898.             }//end Paid Programming
  899.  
  900.             treeItem.setTitle("<b><span class=\"title\">" + treeItem.title + "</span></b>");
  901.             
  902.             if (!ManualRecording)
  903.             {
  904.                 if (description.Length > 0) treeItem.setTitle(treeItem.title + "<span class=\"" + "listdesc" + "\">" + description + "</span>");
  905.  
  906.                 treeItem.setChannelDisplay("<a href=\"" + href + "\"" + onclick + ">" + treeItem.channelDisplay + "</a>");
  907.             }
  908.  
  909.             try
  910.             {
  911.                 treeItem.setProgrammeOID(programme.getOID().ToString()); 
  912.             }
  913.             catch(Exception ex)
  914.             {
  915.                 
  916.             }
  917.  
  918.             string options = "";
  919.             bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
  920.             try
  921.             {
  922.                 switch (scheduledRecording.getRecordingStatus())
  923.                 {
  924.                     case ScheduledRecording.STATUS_PENDING:
  925.                         options = "<br><br><a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small-red\"><span>Cancel Recording</span></a><br>";
  926.                         treeItem.setButtonOptions(options);
  927.                         break;
  928.                     case ScheduledRecording.STATUS_IN_PROGRESS:
  929.                         options = "<br><br><a href=\"" + Download.GetDownloadUrl(false, false, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Play Program</span></a>" +
  930.                                   "<a href=\"" + Download.GetDownloadUrl(true, true, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Download</span></a>";
  931.                         if (strmAllowed)
  932.                         {
  933.                             options += "<a href=\"public/Player.aspx?rid=" + scheduledRecording.getOID() + "&type=mr" + "\" onclick=\"EditPop5(this.href,'Add1');return false;\" class=\"btn-normal-small\"><span>Stream</span></a>";
  934.                         }
  935.                         if (programme == null)
  936.                         {
  937.                             options += "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small-red\"><span>Cancel Recording</span></a>";
  938.                         }
  939.                         options += "<br>";
  940.                         treeItem.setButtonOptions(options);
  941.                         break;
  942.                     case ScheduledRecording.STATUS_COMPLETED:
  943.                         options = "<br><br><a href=\"" + Download.GetDownloadUrl(false, false, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Play Program</span></a>" +
  944.                                   "<a href=\"" + Download.GetDownloadUrl(true, true, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Download</span></a>";
  945.                         if (strmAllowed)
  946.                         {
  947.                             options += "<a href=\"public/Player.aspx?rid=" + scheduledRecording.getOID() + "&type=mr" + "\" onclick=\"EditPop5(this.href,'Add1');return false;\" class=\"btn-normal-small\"><span>Stream</span></a>";
  948.                         }
  949.                         if (programme == null)
  950.                         {
  951.                             options += "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small\"><span>Delete</span></a>";
  952.                         }
  953.                         options += "<br>";
  954.                         treeItem.setButtonOptions(options);
  955.                         break;
  956.                     case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  957.                         options = "<br><br><a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small\"><span>Delete</span></a><br>";
  958.                         treeItem.setButtonOptions(options);
  959.                         break;
  960.                     case ScheduledRecording.STATUS_CONFLICT:
  961.                         options = "<br><br><a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small\"><span>Delete</span></a><br>";
  962.                         treeItem.setButtonOptions(options);
  963.                         break;
  964.                     case ScheduledRecording.STATUS_PLACE_HOLDER:
  965.                         options = "<br><br><a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small-red\"><span>Cancel Recording</span></a><br>";
  966.                         treeItem.setButtonOptions(options);
  967.                         break;
  968.                     case ScheduledRecording.STATUS_DELETED:
  969.                         options = "<br><br><span class=\"title\">" + "Deleted" + "</span><br>";
  970.                         treeItem.setButtonOptions(options);
  971.                         break;
  972.                     default:
  973.                         treeItem.setButtonOptions("NONE!!");
  974.                         break;
  975.                 }
  976.             }
  977.             catch(Exception ex)
  978.             {
  979.                 
  980.             }
  981.             
  982.         }
  983.  
  984.         public void FillProgrammeTree(TreeView treeView, ProgramTreeItem[] treeItemArray, string sortBy, string secondarySortBy)
  985.         {
  986.             SecondarySortBy = secondarySortBy;
  987.             FillProgrammeTree(treeView, treeItemArray, sortBy);
  988.         }
  989.         
  990.         public void FillProgrammeTree(TreeView treeView, ProgramTreeItem [] treeItemArray, string sortBy)
  991.         {
  992.  
  993.             SortBy = sortBy;
  994.             //**************
  995.             //This method Sorts and then loops through an Array of ProgrammeTreeItems to load them into
  996.             //a Treview control that is passed in.
  997.             //**************
  998.             //
  999.  
  1000.             //Pull in the global settings
  1001.             Settings guideParams = Global.Settings;
  1002.  
  1003.             //Create a new sort object for the arrary of TreeItems
  1004.             ProgramTreeItem_Sort sortArray;
  1005.  
  1006.             //Initialize the sort object with the correct sort parameter that defines what order the items will
  1007.             //be sorted in
  1008.             switch (SecondarySortBy)
  1009.             {
  1010.                 case "mrs_title":
  1011.                     {
  1012.                         switch (sortBy)
  1013.                         {
  1014.                             case "title":
  1015.                                 {
  1016.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1017.                                     break;
  1018.                                 }
  1019.                             case "genre":
  1020.                                 {
  1021.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByGenre, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1022.                                     break;
  1023.                                 }
  1024.                             case "rating":
  1025.                                 {
  1026.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1027.                                     break;
  1028.                                 }
  1029.                             case "star":
  1030.                                 {
  1031.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByStarRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1032.                                     break;
  1033.                                 }
  1034.                             case "date":
  1035.                                 {
  1036.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1037.                                     break;
  1038.                                 }
  1039.                             case "originalAirDate":
  1040.                                 {
  1041.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByOriginalAirDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1042.                                     break;
  1043.                                 }
  1044.                             case "mr_title":
  1045.                                 {
  1046.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1047.                                     break;
  1048.                                 }
  1049.                             case "mr_genre":
  1050.                                 {
  1051.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByGenre, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1052.                                     break;
  1053.                                 }
  1054.                             case "mr_rating":
  1055.                                 {
  1056.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1057.                                     break;
  1058.                                 }
  1059.                             case "mr_star":
  1060.                                 {
  1061.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByStarRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1062.                                     break;
  1063.                                 }
  1064.                             case "mr_date":
  1065.                                 {
  1066.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1067.                                     break;
  1068.                                 }
  1069.                             case "mr_channel":
  1070.                                 {
  1071.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByChannel, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1072.                                     break;
  1073.                                 }
  1074.                             case "mr_status":
  1075.                                 {
  1076.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByStatus, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1077.                                     break;
  1078.                                 }
  1079.                             case "mr_original_date":
  1080.                                 {
  1081.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByOrignalAirDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1082.                                     break;
  1083.                                 }
  1084.                             default:
  1085.                                 {
  1086.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByTitle);
  1087.                                     break;
  1088.                                 }
  1089.                         }
  1090.                         break;
  1091.                     }
  1092.                 case "mrs_date":
  1093.                     {
  1094.                         switch (sortBy)
  1095.                         {
  1096.                             case "title":
  1097.                                 {
  1098.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1099.                                     break;
  1100.                                 }
  1101.                             case "genre":
  1102.                                 {
  1103.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByGenre, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1104.                                     break;
  1105.                                 }
  1106.                             case "rating":
  1107.                                 {
  1108.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1109.                                     break;
  1110.                                 }
  1111.                             case "star":
  1112.                                 {
  1113.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByStarRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1114.                                     break;
  1115.                                 }
  1116.                             case "date":
  1117.                                 {
  1118.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1119.                                     break;
  1120.                                 }
  1121.                             case "mr_title":
  1122.                                 {
  1123.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1124.                                     break;
  1125.                                 }
  1126.                             case "mr_genre":
  1127.                                 {
  1128.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByGenre, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1129.                                     break;
  1130.                                 }
  1131.                             case "mr_rating":
  1132.                                 {
  1133.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1134.                                     break;
  1135.                                 }
  1136.                             case "mr_star":
  1137.                                 {
  1138.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByStarRating, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1139.                                     break;
  1140.                                 }
  1141.                             case "mr_date":
  1142.                                 {
  1143.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1144.                                     break;
  1145.                                 }
  1146.                             case "mr_channel":
  1147.                                 {
  1148.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByChannel, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1149.                                     break;
  1150.                                 }
  1151.                             case "mr_status":
  1152.                                 {
  1153.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByStatus, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1154.                                     break;
  1155.                                 }
  1156.                             case "mr_original_date":
  1157.                                 {
  1158.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.mr_sortByOrignalAirDate, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1159.                                     break;
  1160.                                 }
  1161.                             default:
  1162.                                 {
  1163.                                     sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1164.                                     break;
  1165.                                 }
  1166.                         }
  1167.                         break;
  1168.                     }
  1169.                 default:
  1170.                     {
  1171.                         sortArray = new ProgramTreeItem_Sort(ProgramTreeItem_Sort.treeSortOrder.sortByTitle, ProgramTreeItem_Sort.treeSecondarySortOrder.secondarySortByDate);
  1172.                         break;
  1173.                     }
  1174.             }
  1175.  
  1176.             //Sort the array of TreeItems using the custom sort object
  1177.             Array.Sort(treeItemArray, sortArray);             
  1178.  
  1179.             //Initialize looping variables to 0
  1180.             int idx1 = 0;
  1181.             int idx2 = 0;
  1182.  
  1183.             //Initialize all the display nodes for the tree
  1184.             TreeNode alternateRoot = new TreeNode();
  1185.             TreeNode root = new TreeNode();
  1186.             TreeNode child1 = new TreeNode();
  1187.             TreeNode child2 = new TreeNode();
  1188.             TreeNode child3 = new TreeNode();
  1189.             TreeNode child4 = new TreeNode();
  1190.             TreeNode child5 = new TreeNode();
  1191.             TreeNode child6 = new TreeNode();
  1192.             TreeNode child7 = new TreeNode();
  1193.             TreeNode child8 = new TreeNode();
  1194.             TreeNode child9 = new TreeNode();
  1195.             TreeNode child10 = new TreeNode();
  1196.             TreeNode child11 = new TreeNode();
  1197.             TreeNode child12 = new TreeNode();
  1198.  
  1199.             //Loop through all the TreeItems in the array....building the TreeView
  1200.             while (idx1 < treeItemArray.Length)
  1201.             {
  1202.                 //Set idx2 to the previous index number....this is used to compare the current item to the
  1203.                 //previous item that was loaded into the tree....this tells us where to break to build a new node
  1204.                 idx2 = idx1 - 1;
  1205.                 //Set variable treeItem1 to the first array object
  1206.                 ProgramTreeItem treeItem1 = treeItemArray[idx1];
  1207.                 //Initialize the variable treeItem2
  1208.                 ProgramTreeItem treeItem2 = new ProgramTreeItem();
  1209.                 //We only want to set the variable treeItem2 to the previous item in the array if we have already
  1210.                 //loaded the first item in the array....so if the previous index number (idx2) is 0 or greater we
  1211.                 //have processed the first item in the array already
  1212.                 if (idx2 > -1)
  1213.                 {
  1214.                     treeItem2 = treeItemArray[idx2];
  1215.                 }
  1216.                 //If we are on the first item in the array then we need to load the info into the TreeView and move
  1217.                 //on to processing the next array item
  1218.                 if (idx1 == 0)
  1219.                 {
  1220.                     //If the sort is on anything but title we have to build the main grouper node
  1221.                     if (sortBy != "title" && sortBy != "mr_title")
  1222.                     {
  1223.                         if (sortBy == "status" || sortBy == "mr_status")
  1224.                         {
  1225.                             //Set the grouper node to not do anything when the text of the node is clicked on
  1226.                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1227.                             //Set the node text to the current Status.
  1228.                             alternateRoot.Text = treeItem1.status;
  1229.                         }
  1230.                         else if (sortBy == "channel" || sortBy == "mr_channel")
  1231.                         {
  1232.                             //Set the grouper node to not do anything when the text of the node is clicked on
  1233.                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1234.                             //Set the node text to the current Channel
  1235.                             alternateRoot.Text = treeItem1.channelName;
  1236.                         }
  1237.                         else if (sortBy == "originalAirDate" || sortBy == "mr_original_date")
  1238.                         {
  1239.                             //Set the grouper node to not do anything when the text of the node is clicked on
  1240.                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1241.                             //Set the node text to the original air date
  1242.                             if (guideParams.showAirDate)
  1243.                             {
  1244.                                 if (treeItem1.rawOriginalAirDate != null)
  1245.                                 {
  1246.                                     alternateRoot.Text = treeItem1.originalAirDate;
  1247.                                 }
  1248.                                 else
  1249.                                 {
  1250.                                     alternateRoot.Text = "No Original Air Date Found:";
  1251.                                 }
  1252.                             }
  1253.                             else
  1254.                             {
  1255.                                 alternateRoot.Text = "Original Air Date not selected to display in Configuration Tab:";
  1256.                             }
  1257.                         }
  1258.                         else if (sortBy == "genre" || sortBy == "mr_genre")
  1259.                             {
  1260.                                 //Set the grouper node to not do anything when the text of the node is clicked on
  1261.                                 alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1262.                                 //Check to see if the user has selected to show Genre or not....if not then give them
  1263.                                 //a message indicating this.....otherwise set the node text to the current Genre.
  1264.                                 if (guideParams.showGenre != "noGenre")
  1265.                                 {
  1266.                                     alternateRoot.Text = treeItem1.genre;
  1267.                                 }
  1268.                                 else
  1269.                                 {
  1270.                                     alternateRoot.Text = "Genre not selected to display in Configuration Tab:";
  1271.                                 }
  1272.                             }    
  1273.                         else if (sortBy == "rating" || sortBy == "mr_rating")
  1274.                             {
  1275.                                 //Set the grouper node to not do anything when the text of the node is clicked on
  1276.                                 alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1277.                                 //Check to see if the user has selected to show Rating or not....if not then give them
  1278.                                 //a message indicating this.....otherwise set the node text to the current Rating.
  1279.  
  1280.                                 if (guideParams.showRating)
  1281.                                 {
  1282.                                     if (treeItem1.rating != null)
  1283.                                     {
  1284.                                         alternateRoot.Text = treeItem1.rating;
  1285.                                     }
  1286.                                     else
  1287.                                     {
  1288.                                         alternateRoot.Text = "No Rating Found:";
  1289.                                     }
  1290.                                 }
  1291.                                 else
  1292.                                 {
  1293.                                     alternateRoot.Text = "Rating not selected to display in Configuration Tab:";
  1294.                                 }
  1295.                             }
  1296.                         else if (sortBy == "star"  || sortBy == "mr_star")
  1297.                             {
  1298.                                 //Set the grouper node to not do anything when the text of the node is clicked on
  1299.                                 alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1300.                                 //Check to see if the user has selected to show Star Rating or not....if not then give them
  1301.                                 //a message indicating this.....otherwise set the node text to the current Star Rating.
  1302.  
  1303.                                 if (guideParams.showStarRating)
  1304.                                 {
  1305.                                     if (treeItem1.starRating != null)
  1306.                                     {
  1307.                                         alternateRoot.Text = treeItem1.starRating;
  1308.                                     }
  1309.                                     else
  1310.                                     {
  1311.                                         alternateRoot.Text = "No Star Rating Found:";
  1312.                                     }
  1313.                                 }
  1314.                                 else
  1315.                                 {
  1316.                                     alternateRoot.Text = " Star Rating not selected to display in Configuration Tab:";
  1317.                                 }
  1318.                             }
  1319.                         else if (sortBy == "date")
  1320.                             {
  1321.                                 //Set the grouper node to not do anything when the text of the node is clicked onalternateRoot.SelectAction = TreeNodeSelectAction.None;
  1322.                                 if (treeItem1.rawAirDateStartTime != null)
  1323.                                 {
  1324.                                     alternateRoot.Text = treeItem1.airDate;
  1325.                                 }
  1326.                                 else
  1327.                                 {
  1328.                                     alternateRoot.Text = "No Air Date Found:";
  1329.                                 }
  1330.                             }
  1331.                         else if (sortBy == "mr_date")
  1332.                             {
  1333.                                 //Set the grouper node to not do anything when the text of the node is clicked onalternateRoot.SelectAction = TreeNodeSelectAction.None;
  1334.                                 if (treeItem1.rawAirDateStartTime != null)
  1335.                                 {
  1336.                                     alternateRoot.Text = treeItem1.rawAirDateStartTime.ToLongDateString();
  1337.                                 }
  1338.                                 else
  1339.                                 {
  1340.                                     alternateRoot.Text = "No Air Date Found:";
  1341.                                 }
  1342.                             } 
  1343.                     }
  1344.                     //Fill a complete TreeView Item including the top level of the item
  1345.                     root = FillProgrammeTree(treeItem1, guideParams, root, child1, child2, child3, child4, child5,
  1346.                                                 child6, child7, child8, child9, child10, child11, child12, true);
  1347.                 }
  1348.                 else
  1349.                 {
  1350.                     //This code is executed for the second item in the array through the end of the array
  1351.                     //
  1352.                     //If you are either not sorting by the date or if you are sorting by the date and both the current
  1353.                     //item and the previous item have the same air date then we do not need to break for a new node
  1354.                     if ((sortBy == "date" && treeItem1.rawAirDateStartTime == treeItem2.rawAirDateStartTime) ||
  1355.                         (sortBy == "mr_date" && treeItem1.rawAirDateStartTime.ToLongDateString() == treeItem2.rawAirDateStartTime.ToLongDateString()) ||
  1356.                         (sortBy == "mr_originalDate" && treeItem1.rawOriginalAirDate == treeItem2.rawOriginalAirDate) ||
  1357.                         (sortBy == "originalAirDate" && treeItem1.rawOriginalAirDate == treeItem2.rawOriginalAirDate) ||
  1358.                         (sortBy == "mr_channel" && treeItem1.channel == treeItem2.channel) ||
  1359.                         (sortBy == "mr_status" && treeItem1.status == treeItem2.status) ||
  1360.                         (sortBy != "mr_original_Date" && sortBy != "originalAirDate" && sortBy != "date" && sortBy != "mr_date" && sortBy != "mr_channel" && sortBy != "mr_status"))
  1361.                     {
  1362.                         //If the titles of the current and previous item match there is no need to break for a new node
  1363.                         if (treeItem1.rawTitle == treeItem2.rawTitle)
  1364.                         {
  1365.                             //If the subtitles of the current and previous item match there is no need to break for a
  1366.                             //new node
  1367.                             if (treeItem1.subtitle == treeItem2.subtitle)
  1368.                             {
  1369.                                 if (treeItem1.description == treeItem2.description)
  1370.                                 {
  1371.                                     //If this item has a status such as recorded, failed, etc then we need to replace the text so that 
  1372.                                     //it displays with the correct highlighting which is stored in the RecordingDisplayClaiss of the treeItem. 
  1373.                                     if (treeItem1.getRecordingDisplayClass() != "listing")
  1374.                                     {
  1375.                                         child1.Text =
  1376.                                             child1.Text.Replace("class=\"listing\"",
  1377.                                                                 "class=\"" + treeItem1.displayClass + "\"");
  1378.                                         child1.Text =
  1379.                                             child1.Text.Replace("class=\"subtitle\"",
  1380.                                                                 "class=\"" + treeItem1.displayClass + "\"");
  1381.                                     }
  1382.                                     //if the current and previous items are not on the same date we want to have a node
  1383.                                     //break so that we have a node for each date the show is airing on
  1384.                                     if (treeItem1.rawAirDateStartTime != treeItem2.rawAirDateStartTime)
  1385.                                     {
  1386.                                         //Initialize the two treenodes that are needed
  1387.                                         child11 = new TreeNode();
  1388.                                         child12 = new TreeNode();
  1389.                                         //Set the airdate to display
  1390.                                         FillProgrammeTreeAirDate(treeItem1, child11);
  1391.                                         //Set this node to do nothing when the text is clicked on
  1392.                                         child11.SelectAction = TreeNodeSelectAction.None;
  1393.                                         //We want this node to be expanded automatically
  1394.                                         child11.Expand();
  1395.                                         //If this item has a status such as recorded, failed, etc then we need to replace the text so that 
  1396.                                         //it displays with the correct highlighting which is stored in the RecordingDisplayClaiss of the treeItem. 
  1397.                                         if (treeItem1.displayClass != "listing")
  1398.                                         {
  1399.                                             child11.Text =
  1400.                                                 child11.Text.Replace("class=\"listing\"",
  1401.                                                                      "class=\"" + treeItem1.displayClass + "\"");
  1402.                                         }
  1403.                                         //Add the node to the tree
  1404.                                         child1.ChildNodes.Add(child11);
  1405.  
  1406.                                         //Set the channel info in the node
  1407.                                         FillProgrammeTreeChannel(treeItem1, child12);
  1408.                                         //Set the text in the node to do nothing when clicked on
  1409.                                         child12.SelectAction = TreeNodeSelectAction.None;
  1410.                                         //If the treeitem does not have any recording status then we want to let the user
  1411.                                         //select to record the show by using a checkbox
  1412.                                         if (treeItem1.displayClass == "listing")
  1413.                                         {
  1414.                                             child12.ShowCheckBox = true;
  1415.                                         }
  1416.                                         //Add the node to the tree
  1417.                                         child11.ChildNodes.Add(child12);
  1418.                                     }
  1419.                                     else
  1420.                                     {
  1421.                                         //Since the airdates for the current and previous items matched we only need to create
  1422.                                         //a node for the channel that the show is displaying on
  1423.                                         //
  1424.                                         //Initialize the treenode is needed
  1425.                                         child12 = new TreeNode();
  1426.                                         //Set the channel info in the node
  1427.                                         FillProgrammeTreeChannel(treeItem1, child12);
  1428.                                         //Set the text in the node to do nothing when clicked on
  1429.                                         //If the treeitem does not have any recording status then we want to let the user
  1430.                                         //select to record the show by using a checkbox
  1431.                                         child12.SelectAction = TreeNodeSelectAction.None;
  1432.                                         if (treeItem1.displayClass == "listing")
  1433.                                         {
  1434.                                             child12.ShowCheckBox = true;
  1435.                                         }
  1436.                                         child11.ChildNodes.Add(child12);
  1437.                                     }
  1438.                                 }
  1439.                                 else
  1440.                                 {
  1441.                                     //Since the descriptions are different between the current item and the previous item we
  1442.                                     //need to create a new node for all the show info.  However, since the Titles match
  1443.                                     //we do not create a new main root node.
  1444.                                     child1 = new TreeNode();
  1445.                                     child2 = new TreeNode();
  1446.                                     child3 = new TreeNode();
  1447.                                     child4 = new TreeNode();
  1448.                                     child5 = new TreeNode();
  1449.                                     child6 = new TreeNode();
  1450.                                     child7 = new TreeNode();
  1451.                                     child8 = new TreeNode();
  1452.                                     child9 = new TreeNode();
  1453.                                     child10 = new TreeNode();
  1454.                                     child11 = new TreeNode();
  1455.                                     child12 = new TreeNode();
  1456.                                     root = FillProgrammeTree(treeItem1, guideParams, root, child1, child2, child3, child4, child5,
  1457.                                     child6, child7, child8, child9, child10, child11, child12, false); 
  1458.                                 }
  1459.                             }
  1460.                             else
  1461.                             {
  1462.                                 //Since the subtitles are different between the current item and the previous item we
  1463.                                 //need to create a new node for all the show info.  However, since the Titles match
  1464.                                 //we do not create a new main root node.
  1465.                                 child1 = new TreeNode();
  1466.                                 child2 = new TreeNode();
  1467.                                 child3 = new TreeNode();
  1468.                                 child4 = new TreeNode();
  1469.                                 child5 = new TreeNode();
  1470.                                 child6 = new TreeNode();
  1471.                                 child7 = new TreeNode();
  1472.                                 child8 = new TreeNode();
  1473.                                 child9 = new TreeNode();
  1474.                                 child10 = new TreeNode();
  1475.                                 child11 = new TreeNode();
  1476.                                 child12 = new TreeNode();
  1477.                                 root = FillProgrammeTree(treeItem1, guideParams, root, child1, child2, child3, child4, child5,
  1478.                                 child6, child7, child8, child9, child10, child11, child12, false);
  1479.                             }
  1480.                         }
  1481.                         else
  1482.                         {
  1483.                             //Since the Titles of the current and previous item do not match we need to create a
  1484.                             //new node to hold all the show info
  1485.                             //
  1486.                             //If we are not sorting by title then we are grouping by some other characteristic.
  1487.                             if (sortBy != "title" && sortBy != "mr_title")
  1488.                             {
  1489.                                 //Add the new node to the grouping node (alternateRoot)
  1490.                                 alternateRoot.ChildNodes.Add(root);
  1491.                                 //If the grouping item is different between the current item and the previous item then
  1492.                                 //we need to create a new grouping node
  1493.                                 if (sortBy == "mr_status")
  1494.                                     {
  1495.                                         if (treeItem1.status != treeItem2.status)
  1496.                                         {
  1497.                                             //Set the grouper node to not do anything when the text of the node is clicked on
  1498.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1499.                                             //Set the node text to the current Status.
  1500.                                             alternateRoot.Text = treeItem1.status;
  1501.                                         }
  1502.                                     }
  1503.                                 else if (sortBy == "mr_channel")
  1504.                                     {
  1505.                                         if (treeItem1.channel != treeItem2.channel)
  1506.                                         {
  1507.                                             //Set the grouper node to not do anything when the text of the node is clicked on
  1508.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1509.                                             //Set the node text to the current Channel
  1510.                                             alternateRoot.Text = treeItem1.channelName;
  1511.                                         }
  1512.                                     }
  1513.                                 else if (sortBy == "genre" || sortBy == "mr_genre")
  1514.                                     {
  1515.                                         if (treeItem1.genre != treeItem2.genre)
  1516.                                         {
  1517.                                             //Add the grouping node to the treeview
  1518.                                             treeView.Nodes.Add(alternateRoot);
  1519.                                             //Initialize a new grouping node
  1520.                                             alternateRoot = new TreeNode();
  1521.                                             //set the grouping node to do nothing when the text of the node is selected
  1522.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1523.                                             //Check to see if the user has selected to show Genre or not....if not then give them
  1524.                                             //a message indicating this.....otherwise set the node text to the current Genre.
  1525.                                             if (guideParams.showGenre != "noGenre")
  1526.                                             {
  1527.                                                 alternateRoot.Text = treeItem1.genre;
  1528.                                             }
  1529.                                             else
  1530.                                             {
  1531.                                                 alternateRoot.Text = "Genre not selected to display in Configuration Tab:";
  1532.                                             }
  1533.                                         }
  1534.                                     }
  1535.                                 else if (sortBy == "rating" || sortBy == "mr_rating")
  1536.                                     {
  1537.                                         if (treeItem1.rating != treeItem2.rating)
  1538.                                         {
  1539.                                             //Add the grouping node to the treeview
  1540.                                             treeView.Nodes.Add(alternateRoot);
  1541.                                             //Initialize a new grouping node
  1542.                                             alternateRoot = new TreeNode();
  1543.                                             //set the grouping node to do nothing when the text of the node is selected
  1544.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1545.                                             //Check to see if the user has selected to show Rating or not....if not then give them
  1546.                                             //a message indicating this.....otherwise set the node text to the current Rating.
  1547.  
  1548.                                             if (guideParams.showRating)
  1549.                                             {
  1550.                                                 if (treeItem1.rating != null)
  1551.                                                 {
  1552.                                                     alternateRoot.Text = treeItem1.rating;
  1553.                                                 }
  1554.                                                 else
  1555.                                                 {
  1556.                                                     alternateRoot.Text = "No Rating Found:";
  1557.                                                 }
  1558.                                             }
  1559.                                             else
  1560.                                             {
  1561.                                                 alternateRoot.Text = "Rating not selected to display in Configuration Tab:";
  1562.                                             }
  1563.                                         }
  1564.                                     }
  1565.                                 else if (sortBy == "star" || sortBy == "mr_star")
  1566.                                     {
  1567.                                         if (treeItem1.starRating != treeItem2.starRating)
  1568.                                         {
  1569.                                             //Add the grouping node to the treeview
  1570.                                             treeView.Nodes.Add(alternateRoot);
  1571.                                             //Initialize a new grouping node
  1572.                                             alternateRoot = new TreeNode();
  1573.                                             //set the grouping node to do nothing when the text of the node is selected
  1574.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1575.                                             //Check to see if the user has selected to show Star Rating or not....if not then give them
  1576.                                             //a message indicating this.....otherwise set the node text to the current Star Rating.
  1577.                                             if (guideParams.showStarRating)
  1578.                                             {
  1579.                                                 if (treeItem1.starRating != null)
  1580.                                                 {
  1581.                                                     alternateRoot.Text = treeItem1.starRating;
  1582.                                                 }
  1583.                                                 else
  1584.                                                 {
  1585.                                                     alternateRoot.Text = "No Star Rating Found:";
  1586.                                                 }
  1587.                                             }
  1588.                                             else
  1589.                                             {
  1590.                                                 alternateRoot.Text = "Star Rating not selected to display in Configuration Tab:";
  1591.                                             }
  1592.                                         }
  1593.                                     }
  1594.                                else if (sortBy == "originalAirDate" || sortBy == "mr_original_date")
  1595.                                     {
  1596.                                         if (treeItem1.rawOriginalAirDate != treeItem2.rawOriginalAirDate)
  1597.                                         {
  1598.                                             //Add the grouping node to the treeview
  1599.                                             treeView.Nodes.Add(alternateRoot);
  1600.                                             //Initialize a new grouping node
  1601.                                             alternateRoot = new TreeNode();
  1602.                                             //set the grouping node to do nothing when the text of the node is selected
  1603.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1604.                                             //Check to see if the user has selected to show Star Rating or not....if not then give them
  1605.                                             //a message indicating this.....otherwise set the node text to the current Star Rating.
  1606.                                             if (guideParams.showAirDate)
  1607.                                             {
  1608.                                                 if (treeItem1.rawOriginalAirDate != null)
  1609.                                                 {
  1610.                                                     alternateRoot.Text = treeItem1.originalAirDate;
  1611.                                                 }
  1612.                                                 else
  1613.                                                 {
  1614.                                                     alternateRoot.Text = "No Orignal Air Date Found:";
  1615.                                                 }
  1616.                                             }
  1617.                                             else
  1618.                                             {
  1619.                                                 alternateRoot.Text = "Orignal Air Date not selected to display in Configuration Tab:";
  1620.                                             }
  1621.                                         }
  1622.                                     }
  1623.                                 else if (sortBy == "date")
  1624.                                     {
  1625.                                         if (treeItem1.rawAirDateStartTime != treeItem2.rawAirDateStartTime ||
  1626.                                            (treeItem1.rawAirDateStartTime == treeItem2.rawAirDateStartTime && treeItem1.rawAirDateEndTime != treeItem2.rawAirDateEndTime))
  1627.                                         {
  1628.                                             //Add the grouping node to the treeview
  1629.                                             treeView.Nodes.Add(alternateRoot);
  1630.                                             //Initialize a new grouping node
  1631.                                             alternateRoot = new TreeNode();
  1632.                                             //set the grouping node to do nothing when the text of the node is selected
  1633.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1634.                                             if (treeItem1.rawAirDateStartTime != null)
  1635.                                             {
  1636.                                                 alternateRoot.Text = treeItem1.airDate;
  1637.                                             }
  1638.                                             else
  1639.                                             {
  1640.                                                 alternateRoot.Text = "No Air Date Found:";
  1641.                                             }
  1642.                                         }
  1643.                                     }
  1644.                                 else if (sortBy == "mr_date")
  1645.                                     {
  1646.                                         if (treeItem1.rawAirDateStartTime.ToLongDateString() != treeItem2.rawAirDateStartTime.ToLongDateString())
  1647.                                         {
  1648.                                             //Add the grouping node to the treeview
  1649.                                             treeView.Nodes.Add(alternateRoot);
  1650.                                             //Initialize a new grouping node
  1651.                                             alternateRoot = new TreeNode();
  1652.                                             //set the grouping node to do nothing when the text of the node is selected
  1653.                                             alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1654.                                             if (treeItem1.rawAirDateStartTime != null)
  1655.                                             {
  1656.                                                 alternateRoot.Text = treeItem1.rawAirDateStartTime.ToLongDateString();
  1657.                                             }
  1658.                                             else
  1659.                                             {
  1660.                                                 alternateRoot.Text = "No Air Date Found:";
  1661.                                             }
  1662.                                         }
  1663.                                     } 
  1664.                             }
  1665.                             else
  1666.                             {
  1667.                                 //Since we are sorting by title we just add the node to the TreeView
  1668.                                 treeView.Nodes.Add(root);
  1669.                             }
  1670.                             //Initalize the nodes 
  1671.                             root = new TreeNode();
  1672.                             child1 = new TreeNode();
  1673.                             child2 = new TreeNode();
  1674.                             child3 = new TreeNode();
  1675.                             child4 = new TreeNode();
  1676.                             child5 = new TreeNode();
  1677.                             child6 = new TreeNode();
  1678.                             child7 = new TreeNode();
  1679.                             child8 = new TreeNode();
  1680.                             child9 = new TreeNode();
  1681.                             child10 = new TreeNode();
  1682.                             child11 = new TreeNode();
  1683.                             child12 = new TreeNode();
  1684.                             //Fill the intialized nodes with the info in the current item.  Since this is a non-matching
  1685.                             //item then we also initialize the main root node.
  1686.                             root = FillProgrammeTree(treeItem1, guideParams, root, child1, child2, child3, child4, child5,
  1687.                                 child6, child7, child8, child9, child10, child11, child12, true);
  1688.                         }
  1689.                     }
  1690.                     else
  1691.                     {
  1692.                         //Since we are soting by date and the dates of the current and previous item do not match we
  1693.                         //need to make a break and create a new node to hold the info
  1694.                         //
  1695.                         //Add the node to the grouping node
  1696.                         alternateRoot.ChildNodes.Add(root);
  1697.                         //Add the grouping node to the TreeView
  1698.                         treeView.Nodes.Add(alternateRoot);
  1699.                         //Initialize a new grouping node
  1700.                         alternateRoot = new TreeNode();
  1701.                         //Set the grouping node text to do nothing when clicked on
  1702.                         alternateRoot.SelectAction = TreeNodeSelectAction.None;
  1703.                         if (sortBy == "mr_date" || sortBy == "date")
  1704.                         {
  1705.                             if (treeItem1.rawAirDateStartTime != null)
  1706.                             {
  1707.                                 if (sortBy == "mr_date")
  1708.                                 {
  1709.                                     alternateRoot.Text = treeItem1.rawAirDateStartTime.ToLongDateString();
  1710.                                 }
  1711.                                 else
  1712.                                 {
  1713.                                     alternateRoot.Text = treeItem1.airDate;
  1714.                                 }
  1715.                             }
  1716.                             else
  1717.                             {
  1718.                                 alternateRoot.Text = "No Air Date Found:";
  1719.                             }
  1720.                         }
  1721.                         else if (sortBy == "originalAirDate" || sortBy == "mr_original_date")
  1722.                         {
  1723.                             if (guideParams.showAirDate)
  1724.                             {
  1725.                                 if (treeItem1.rawOriginalAirDate != null)
  1726.                                 {
  1727.                                     alternateRoot.Text = treeItem1.originalAirDate;
  1728.                                 }
  1729.                                 else
  1730.                                 {
  1731.                                     alternateRoot.Text = "No Original Air Date Found:";
  1732.                                 }
  1733.                             }
  1734.                             else
  1735.                             {
  1736.                                 alternateRoot.Text = "Original Air Date not selected to display in Configuration Tab:";
  1737.                             }
  1738.                         }
  1739.                         else if (sortBy == "mr_channel")
  1740.                         {
  1741.                             alternateRoot.Text = treeItem1.channelName;
  1742.                         }
  1743.                         else
  1744.                         {
  1745.                             alternateRoot.Text = treeItem1.status;
  1746.                         }
  1747.                         //Initalize the nodes 
  1748.                         root = new TreeNode();
  1749.                         child1 = new TreeNode();
  1750.                         child2 = new TreeNode();
  1751.                         child3 = new TreeNode();
  1752.                         child4 = new TreeNode();
  1753.                         child5 = new TreeNode();
  1754.                         child6 = new TreeNode();
  1755.                         child7 = new TreeNode();
  1756.                         child8 = new TreeNode();
  1757.                         child9 = new TreeNode();
  1758.                         child10 = new TreeNode();
  1759.                         child11 = new TreeNode();
  1760.                         child12 = new TreeNode();
  1761.                         //Fill the intialized nodes with the info in the current item.  Since this is a non-matching
  1762.                         //item then we also initialize the main root node.
  1763.                         root = FillProgrammeTree(treeItem1, guideParams, root, child1, child2, child3, child4, child5,
  1764.                             child6, child7, child8, child9, child10, child11, child12, true);
  1765.                     }
  1766.                 }
  1767.                 //Up the index of the loop
  1768.                 idx1++;
  1769.             }
  1770.  
  1771.             //If you are not sorting by title then load the last node filed to the grouping node and then
  1772.             //the grouping node to the TreeView otherwise just load the node to the Treeview
  1773.             if (sortBy != "title" && sortBy != "mr_title")
  1774.             {
  1775.                 alternateRoot.ChildNodes.Add(root);
  1776.                 treeView.Nodes.Add(alternateRoot);
  1777.             }
  1778.             else
  1779.             {
  1780.                 treeView.Nodes.Add(root);
  1781.             }
  1782.         }
  1783.  
  1784.         private TreeNode FillProgrammeTree(ProgramTreeItem treeItem1, Settings guideParams, TreeNode root, TreeNode child1,
  1785.                                                 TreeNode child2, TreeNode child3, TreeNode child4, TreeNode child5,
  1786.                                                 TreeNode child6, TreeNode child7, TreeNode child8, TreeNode child9,
  1787.                                                 TreeNode child10, TreeNode child11, TreeNode child12, bool fillRoot)
  1788.         {
  1789.             //**************
  1790.             //This method loads the nodes that will ultimatley be loaded into a TreeView control for displaying program
  1791.             //information.
  1792.             //**************
  1793.             //
  1794.             if (fillRoot)
  1795.             {
  1796.                 FillProgrammeTreeTitle(treeItem1, root);
  1797.             }
  1798.             FillProgrammeTreeSubTitle(treeItem1, child1);
  1799.             root.ChildNodes.Add(child1);
  1800.  
  1801.             if (guideParams.showDescription)
  1802.             {
  1803.                 FillProgrammeTreeDescription(treeItem1, child2, child3);
  1804.                 
  1805.                 //If the description is empty do not display it.
  1806.                 if (child3.Text.Length > 0)
  1807.                 {
  1808.                     child1.ChildNodes.Add(child2);
  1809.                     child3.SelectAction = TreeNodeSelectAction.None;
  1810.                     child2.ChildNodes.Add(child3);
  1811.                 }
  1812.             }
  1813.  
  1814.             FillProgrammeTreeCommon(treeItem1, child4, child5, child6, child7, child8, child9, child10);
  1815.             if (guideParams.showRating)
  1816.             {
  1817.                 // Create Child Node for rating
  1818.                 if (child4.Text != String.Empty)
  1819.                 {
  1820.                     child4.SelectAction = TreeNodeSelectAction.None;
  1821.                     child1.ChildNodes.Add(child4);
  1822.                 }
  1823.             }
  1824.  
  1825.             if (guideParams.showGenre != "noGenre")
  1826.             {
  1827.                 // Create Child Node for Genre
  1828.                 if (child5.Text != String.Empty)
  1829.                 {
  1830.                     child5.SelectAction = TreeNodeSelectAction.None;
  1831.                     child1.ChildNodes.Add(child5);
  1832.                 }
  1833.             }
  1834.  
  1835.             if (guideParams.showAirDate)
  1836.             {
  1837.                 // Create Child Node for Release Year
  1838.                 if (child6.Text != String.Empty)
  1839.                 {
  1840.                     child6.SelectAction = TreeNodeSelectAction.None;
  1841.                     child1.ChildNodes.Add(child6);
  1842.                 }
  1843.             }
  1844.  
  1845.             if (guideParams.showStarRating)
  1846.             {
  1847.                 // Create Child Node for Star Rating
  1848.                 if (child7.Text != String.Empty)
  1849.                 {
  1850.                     child7.SelectAction = TreeNodeSelectAction.None;
  1851.                     child1.ChildNodes.Add(child7);
  1852.                 }
  1853.             }
  1854.  
  1855.             if (guideParams.showAirDate)
  1856.             {
  1857.                 // Create Child Node for Original Air Date
  1858.                 if (child8.Text != String.Empty)
  1859.                 {
  1860.                     child8.SelectAction = TreeNodeSelectAction.None;
  1861.                     child1.ChildNodes.Add(child8);
  1862.                 }
  1863.             }
  1864.  
  1865.             if (guideParams.showNew)
  1866.             {
  1867.                 // Create Child Node for a new show
  1868.                 if (child9.Text != String.Empty)
  1869.                 {
  1870.                     child9.SelectAction = TreeNodeSelectAction.None;
  1871.                     child1.ChildNodes.Add(child9);
  1872.                 }
  1873.             }
  1874.  
  1875.             if (guideParams.showCredits)
  1876.             {
  1877.                 // Create Child Node for Credits
  1878.                 if (child10.Text != String.Empty)
  1879.                 {
  1880.                     child10.SelectAction = TreeNodeSelectAction.None;
  1881.                     child1.ChildNodes.Add(child10);
  1882.                 }
  1883.             }
  1884.  
  1885.             //Set the 12th level of the tree for the show to the Date and time the show is available
  1886.             FillProgrammeTreeAirDate(treeItem1, child11);
  1887.             child11.SelectAction = TreeNodeSelectAction.None;
  1888.             child11.Expand();
  1889.             child1.ChildNodes.Add(child11);
  1890.  
  1891.             //Set the 13th level of the tree for the show to the Channel which has a check box for multi-recording selection option
  1892.             FillProgrammeTreeChannel(treeItem1, child12);
  1893.             child12.SelectAction = TreeNodeSelectAction.None;
  1894.             if (treeItem1.displayClass == "listing")
  1895.             {
  1896.                 child12.ShowCheckBox = true;
  1897.             }
  1898.             child11.ChildNodes.Add(child12);
  1899.  
  1900.             return (root);
  1901.  
  1902.         }
  1903.  
  1904.         #region Methods that load TreeNodes with info from a ProgrammeTreeItem Object
  1905.  
  1906.         private void FillProgrammeTreeTitle(ProgramTreeItem treeItem, TreeNode treeNode)
  1907.         {
  1908.             treeNode.Text = treeItem.title;
  1909.             treeNode.SelectAction = TreeNodeSelectAction.None;
  1910.             treeNode.Expand();
  1911.         }
  1912.  
  1913.         private void FillProgrammeTreeSubTitle(ProgramTreeItem treeItem, TreeNode treeNode)
  1914.         {
  1915.             treeNode.Text = treeItem.subtitle;
  1916.             if (treeItem.displayClass != "listing")
  1917.             {
  1918.                 treeNode.Text = treeNode.Text.Replace("class=\"listing\"", "class=\"" + treeItem.displayClass + "\"");
  1919.                 treeNode.Text = treeNode.Text.Replace("class=\"subtitle\"", "class=\"" + treeItem.displayClass + "\"");
  1920.             }
  1921.             treeNode.SelectAction = TreeNodeSelectAction.None;
  1922.             if (SortBy != null && SortBy.Length > 2)
  1923.             {
  1924.                 if (treeItem.status == "Reocurring")
  1925.                 {
  1926.                     treeNode.Text = "Season Recording" + treeNode.Text;
  1927.                 }
  1928.                 else
  1929.                 {
  1930.                     if (treeItem.rawOriginalAirDate != null)
  1931.                     {
  1932.                         treeNode.Text = "(ad: " + treeItem.rawAirDateStartTime.ToShortDateString() + ") " + treeNode.Text + "  (oad: " + treeItem.rawOriginalAirDate + ")";
  1933.                     }
  1934.                     else
  1935.                     {
  1936.                         treeNode.Text = "(ad: " + treeItem.rawAirDateStartTime.ToShortDateString() + ") " + treeNode.Text;
  1937.                     }                        
  1938.                 }
  1939.             }
  1940.         }
  1941.  
  1942.         private void FillProgrammeTreeDescription(ProgramTreeItem treeItem, TreeNode treeNode1, TreeNode treeNode2)
  1943.         {
  1944.             treeNode1.Text = "<span class=\"listing\">" + "Description:" + "</span>";
  1945.             treeNode1.SelectAction = TreeNodeSelectAction.None;
  1946.             treeNode1.Expand();
  1947.  
  1948.             treeNode2.Text = treeItem.description;
  1949.         }
  1950.  
  1951.         private void FillProgrammeTreeCommon(ProgramTreeItem treeItem, TreeNode treeNode1, TreeNode treeNode2, TreeNode treeNode3, TreeNode treeNode4, TreeNode treeNode5, TreeNode treeNode6, TreeNode treeNode7)
  1952.         {
  1953.             treeNode1.Text = treeItem.rating;
  1954.  
  1955.             treeNode2.Text = treeItem.genre;
  1956.  
  1957.             treeNode3.Text = treeItem.releaseYear;
  1958.  
  1959.             treeNode4.Text = treeItem.starRating;
  1960.  
  1961.             treeNode5.Text = treeItem.originalAirDate;
  1962.  
  1963.             treeNode6.Text = treeItem.new_show;
  1964.  
  1965.             treeNode7.Text = treeItem.credits;
  1966.  
  1967.         }
  1968.  
  1969.         private void FillProgrammeTreeAirDate(ProgramTreeItem treeItem, TreeNode treeNode)
  1970.         {
  1971.             treeNode.Text = treeItem.getAirDate();
  1972.             if (treeItem.getRecordingDisplayClass() != "listing")
  1973.             {
  1974.                 treeNode.Text = treeNode.Text.Replace("class=\"listing\"", "class=\"" + treeItem.displayClass + "\"");
  1975.             }
  1976.         }
  1977.  
  1978.         private void FillProgrammeTreeChannel(ProgramTreeItem treeItem, TreeNode treeNode)
  1979.         {
  1980.             treeNode.Text = treeItem.channelDisplay;
  1981.             treeNode.Value = treeItem.programmeOID;
  1982.             treeNode.Text += treeItem.buttonOptions;
  1983.         }
  1984.         #endregion
  1985.     }
  1986. }
  1987.